# _*_ coding: utf8
'''
author: ning.luo
create_date: 2019/03/04
last_update: 2019/03/04
'''

import requests
import unittest
import json

class Aftersale_inquire(unittest.TestCase):
    '''外部售后查询相关接口'''

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test01_multiple_inquire_OMG(self):
        '''备货批量查询售后服务'''
        headers = {"Content-Type": "application/json", "charset": "UTF-8"}
        url = "http://test-api.intra.casstime.com/salepolicyv2-service/aftersalepolicys/multiquery"
        params = {
            "areaCode": "",
            "businessType": "",
            "companyId": "14305",
            "queryLines": [
                {
                    "id":"15102969376412040117",
                    "productId":"15102969376412040117"
                }
            ],
            "userLoginId": "cassln1996"
        }
        response = requests.post(url, data=json.dumps(params), headers=headers)
        print(response.text)
        try:
            self.assertEqual(response.status_code, 200)
            j = json.loads(response.text)
            self.assertEqual("ReturnAndChangePolicy", j["datas"][0]["policys"][0]["key"])
            self.assertEqual("3D", j["datas"][0]["policys"][0]["value"])
        except Exception as e:
            print("Http状态码：", response.status_code)
            print("返回结果：", response.text)
            raise e

    def test02_multiple_inquire_BK(self):
        '''询价批量查询售后服务'''
        headers = {"Content-Type": "application/json", "charset": "UTF-8"}
        url = "http://test-api.intra.casstime.com/salepolicyv2-service/aftersalepolicys/multiquery"
        params = {
	        "userLoginId": "wlefntwcpobys8y3sz2",
	        "companyId": "EZtleiWNOJtPQZubA41",
	        "queryLines":[
                {
                    "id": "5bd69bdd7ca1f63cbe07fcde",
                    "storeId": "GZZQ0001",
                    "brandCode": "BMW",
                    "oeCode": "13 71 7 548 898",
                    "partsBrandCode": "AC DELCO",
                    "brandQualityId": "EXTERNAL_BRAND",
                    "supply": "transfer",  # 调货
                    "price4s": 34
                },
                {
                    "id": "5bd69bdd7ca1f63cbe07fabc",
                    "storeId": "GZYT0001",
                    "brandCode": "BMW",
                    "oeCode": "12 12 0 037 244",
                    "partsBrandCode": "BMW",
                    "brandQualityId": "ORIGINAL_BRAND",
                    "supply": "spot",  # 现货
                    "price4s": 34
                }
            ]
        }
        response = requests.post(url, data=json.dumps(params), headers=headers)
        try:
            self.assertEqual(response.status_code, 200)
            j = json.loads(response.text)
            print(j)
            # self.assertEqual("InstallAssurePolicy", j["datas"][0]["policys"][0]["key"])
            # self.assertEqual("true", j["datas"][0]["policys"][0]["value"])
            # self.assertEqual("InstallAssurePolicy", j["datas"][1]["policys"][0]["key"])
            # self.assertEqual("true", j["datas"][0]["policys"][0]["value"])
        except Exception as e:
            print("Http状态码：", response.status_code)
            print("返回结果：", response.text)
            raise e